package cn.sytton.taffe.web.flw.controller;

import cn.sytton.taffe.framework.base.entity.PageParam;
import cn.sytton.taffe.web.flw.entity.FlowTaskEntity;
import cn.sytton.taffe.web.flw.service.IFlowRunService;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 流程运行 控制层
 *
 * @author skyrock
 */
@Tag(name = "工作流运行")
@RequiredArgsConstructor
@RestController
@RequestMapping("/flw/flow-run")
public class FlowRunController {

    private final IFlowRunService flowRunService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "查询待办分页列表")
    @Parameter(name = "pp", description = "分页参数对象", in = ParameterIn.QUERY, required = true)
    @GetMapping("/todo/page")
    public PageInfo<FlowTaskEntity> findTodoPage(PageParam pp) {
        return flowRunService.findTodoPage(pp);
    }

    @ApiOperationSupport(order = 3)
    @Operation(summary = "查询流程历史记录列表")
    @Parameter(name = "processInstanceId", description = "流程实例ID", in = ParameterIn.PATH, required = true)
    @GetMapping("/task/his/{processInstanceId}")
    public List<FlowTaskEntity> findTaskByProcessInstanceId(@PathVariable String processInstanceId) {
        return flowRunService.findTaskByProcessInstanceId(processInstanceId);
    }

    @ApiOperationSupport(order = 4)
    @Operation(summary = "查询Task")
    @Parameter(name = "taskId", description = "流程TaskId", in = ParameterIn.PATH, required = true)
    @GetMapping("/task/{taskId}")
    public List<Map<String, Object>> findTaskById(@PathVariable String taskId) {
        return flowRunService.findTaskById(taskId);
    }
}
